import { buildColumns } from '@/utils'

export default function useTableColumn() {
  const columns = computed(() =>
    buildColumns([
      {
        title: '文件后缀',
        dataIndex: 'suffix',
        slotName: 'suffix',
        fixed: 'left'
      },
      {
        title: '缓存时间',
        dataIndex: 'cache_time',
        slotName: 'cache_time',
        width: 200
      },
      {
        title: '操作',
        width: 120,
        slotName: 'action'
      }
    ])
  )
  const TimeUnitConversion = (time: string) => {
    if (time) {
      const unit = time.slice(-1) // 取最后一个字符
      const val = time.slice(0, -1) // 取除最后一个字符外的其余字符
      return `${val} ${unit === 's' ? '秒' : unit === 'm' ? '分钟' : unit === 'h' ? '小时' : unit === 'd' ? '天' : '秒'}`
    } else {
      return '-'
    }
  }
  return {
    columns,
    TimeUnitConversion
  }
}
